//
//  KSearchPushVController.m
//  KCZ_B段项目
//
//  Created by dllo on 15/11/9.
//  Copyright © 2015年 Sky. All rights reserved.
//

#import "KSearchPushVController.h"
#import "FitHeader.h"
#import "KShiDetaiTableCell.h"
#import "KShiDetailCaiModel.h"
#import "HTTPMethod.h"
#import "changeString.h"
#import <MBProgressHUD.h>
#import "KMethodViewController.h"
#import "Loading.h"
@interface KSearchPushVController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSMutableArray *dataArray;
@property(nonatomic, strong)Loading *load;
@end

@implementation KSearchPushVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    NSMutableArray *array = [NSMutableArray array];
    for (NSInteger i = 0; i < 70; i++) {
        [array addObject:[NSString stringWithFormat:@"%ld", i + 1]];
    }
    _load = [[Loading alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT - 64 - 49) PicArray:array];
    [self.view addSubview:_load];
    // Do any additional setup after loading the view.
}
-(void)loadView
{
    [super loadView];
    [self getData];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT - 49)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc]init];
    [self.view addSubview:_tableView];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    KShiDetailCaiModel *model = [[KShiDetailCaiModel alloc]init];
    model = _dataArray[indexPath.row];
    KMethodViewController *kvc = [[KMethodViewController alloc]init];
    kvc.methodID = model.dishes_id;
    [self.navigationController pushViewController:kvc animated:YES];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    KShiDetaiTableCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[KShiDetaiTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.model = _dataArray[indexPath.row];

    return cell;
}
-(void)getData
{
    _dataArray = [NSMutableArray array];
    NSString *postUrlString = @"http://api.izhangchu.com/";
    NSString *bodyString = [NSString stringWithFormat:@"page=1&methodName=SearchDishes&size=10&keyword=%@&version=4.02", _searchString];
    [HTTPMethod getDataByString:postUrlString BodyDic:[changeString changeStringToDictionary:bodyString] WithDataBlock:^(id data) {
        NSDictionary *dataDic = [data objectForKey:@"data"];
        NSArray *array = [dataDic objectForKey:@"data"];
        for (NSDictionary *dic in array) {
            KShiDetailCaiModel *model = [[KShiDetailCaiModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [_dataArray addObject:model];
        }
        [_tableView reloadData];
        [_load removeFromSuperview];
    }];

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120 * ht;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
